package edu.spec.chenli.Servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Date;

@WebServlet(name = "fs",urlPatterns = {"/fs"})
public class FirstServlet extends HttpServlet {
    @Override
    public void init() throws ServletException {
        super.init();
        System.out.println(new Date());
    }

    public void service(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException{
        //设置解码方式
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charSet=utf-8");
        //获取所定义的请求参数值
        String name=request.getParameter("name");
        String gender=request.getParameter("gender");
        String[] color=request.getParameterValues("color");
        String national=request.getParameter("country");
        //获取页面输出流
        PrintStream out=new PrintStream(response.getOutputStream());
        //输出HTML页面标签
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet测试</title>");
        out.println("</head>");
        out.println("<body>");
        //输出请求参数
        out.println("你的名字:"+name+"<hr/>");
        out.println("你的性别:"+gender+"<hr/>");
        out.println("你喜欢的颜色：");
        for(String c:color){
            out.println(c+" ");
        }
        out.println("<hr/>");
        out.println("你来自的国家："+national+"<hr/>");
        out.println("</body>");
        out.println("</html>");
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
